﻿using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Input;
using System.Linq;

namespace Vtron.HipcConfigurationTools
{
    public class CodecConnectViewModel : INotifyPropertyChanged
    {
        public string HeaderInfo { get; set; }

        public CodecConnectViewModel()
        {
            EncodedCodecList = new ObservableCollection<CodecInfo>();
            DecodeComboList = new ObservableCollection<CodecInfo>();
            SubmitCommand = new DelegateCommand<string>(Submit);

            MainWindow mainWindow = App.Current.Windows[0] as MainWindow;
            //foreach (CodecInfo codecInfo in mainWindow.EncodedViewModel.CodecInfoes)
            //{
            //    EncodedCodecList.Add(codecInfo);
            //}

            //foreach (CodecInfo codecInfo in mainWindow.DecodeViewModel.CodecInfoes)
            //{
            //    DecodeComboList.Add(codecInfo);
            //}

            foreach (CodecInfo codecInfo in mainWindow.CodecListViewModel.CodecInfoes)
            {
                if (codecInfo.CodecType == "编码器")
                {
                    EncodedCodecList.Add(codecInfo);
                }
                else if (codecInfo.CodecType == "解码器")
                {
                    DecodeComboList.Add(codecInfo);
                }
            }
        }

        private void Submit(string obj)
        {
            //TODO:
        }

        public ObservableCollection<CodecInfo> EncodedCodecList { get; private set; }
        public ObservableCollection<CodecInfo> DecodeComboList { get; private set; }
        public ICommand SubmitCommand { get; private set; }
        public ICommand CancelCommand { get; private set; }

        private CodecInfo decodeSelectedItem;

        public CodecInfo DecodeSelectedItem
        {
            get { return decodeSelectedItem; }
            set
            {
                decodeSelectedItem = value;

                if (PropertyChanged != null)
                {
                    PropertyChanged.Invoke(this, new PropertyChangedEventArgs("DecodeSelectedItem"));
                }
            }
        }

        private CodecInfo encodedSelectedItem;

        public CodecInfo EncodedSelectedItem
        {
            get { return encodedSelectedItem; }
            set
            {
                encodedSelectedItem = value;

                if (PropertyChanged != null)
                {
                    PropertyChanged.Invoke(this, new PropertyChangedEventArgs("DecodeSelectedItem"));
                }
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }
}
